/**
 * Created by Maibenben on 2017/5/6.
 */
$(function () {
    //跳转到本页之后读取cookie中是否有mid和token
    checkCookie();
    var a_id;//用来储存
    //评价内容字数限定在300以内
    $('#text').on('keyup', function () {
        var textval = $(this).val().length;
        if (textval > 300) {
            $('.num').html(300)
        } else {
            $('.num').html(textval)
        }
        if (textval >= 300) {
            var num = $("#text").val().substr(0, 300);
            $('#text').val(num);
        }
    });
    $('li').on('touchstart', function () {
        $('li').removeClass('cur');
        var index = $(this).index() + 1;
        a_id = index;
        for (var j = 0; j < index; j++) {
            $('li').eq(j).addClass('cur')
        }
    });
    //点击发布将用户评价发送到后台
    $(".footer").on("click", function () {
        $.post(commentURL, {
            mid: $.cookie("mid"),
            token: $.cookie("token"),
            d_id: location.search.slice(4),
            a_id: a_id,
            content: $("#text").val()
        }, function () {
            window.location.href = "my-appoint.html";
        });
    });
});